#include <iostream>
#include <string>
#include <vector>

void gcj_2011_r0_b()
{
	char combined[26][26] = {0};    // combined['Q']['F'] => 'T'
	unsigned int opposed[26] = {0}; // opposed mask; bit 0 to 25 are used

	// Input combined sequence, e.g. QFT means [Q,F] => [T]
	int ncombined = 0;
	std::cin >> ncombined;
	for (int i = 0; i < ncombined; i++)
	{
		std::string s;
		std::cin >> s;
		combined[s[0]-'A'][s[1]-'A'] = s[2];
		combined[s[1]-'A'][s[0]-'A'] = s[2];
	}

	// Input opposed sequence, e.g. QE means Q and E are opposed
	int nopposed = 0;
	std::cin >> nopposed;
	for (int i = 0; i < nopposed; i++)
	{
		std::string s;
		std::cin >> s;
		opposed[s[0]-'A'] |= (1 << (s[1]-'A'));
		opposed[s[1]-'A'] |= (1 << (s[0]-'A'));
	}

	// Translate string
	unsigned int exists = 0;
	int count[26] = {0};
	int nlen = 0;
	std::cin >> nlen;
	std::string s, t;
	std::cin >> s;
	for (int i = 0; i < nlen; i++)
	{
		char c = s[i];
		if (t.size() == 0)
		{
			t.push_back(c);
			++count[c-'A'];
			exists |= (1 << (c-'A'));
		}
		else
		{
			char p = t.back();
			if (combined[c-'A'][p-'A'])
			{
				// Combine
				if (--count[p-'A'] == 0)
					exists &= ~(1 << (p-'A'));
				p = combined[c-'A'][p-'A'];
				t.back() = p;
				if (++count[p-'A'] == 1)
					exists |= (1 << (p-'A'));
			}
			else if (exists & opposed[c-'A'])
			{
				// Oppose
				t.clear();
				exists = 0;
				for (int j = 0; j < 26; j++)
					count[j] = 0;
			}
			else
			{
				t.push_back(c);
				++count[c-'A'];
				exists |= (1 << (c-'A'));
			}
		}
	}

	// Output
	std::cout << '[';
	for (int i = 0; i < (int)t.size(); i++)
	{
		if (i > 0)
			std::cout << ", ";
		std::cout << t[i];
	}
	std::cout << ']' << std::endl;
}
